package solution;

import java.util.*;

public class Test {
    //宝石与石头
    public int numJewelsInStones(String jewels, String stones) {
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < jewels.length(); i++) {
            set.add(jewels.charAt(i));
        }
        int count = 0;
        for (int i = 0; i < stones.length(); i++) {
            if(set.contains(stones.charAt(i))) {
                count++;
            }
        }
        return count;
    }

    public static void solution1() {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String str1 = in.nextLine();
            String str2 = in.nextLine();
            func(str1,str2);
        }
    }
    //坏键盘打字
    private static void func(String str1,String str2) {
        Set<Character> set = new HashSet<>();
        str1 = str1.toUpperCase();
        str2 = str2.toUpperCase();
        for (int i = 0; i < str2.length(); i++) {
            set.add(str2.charAt(i));
        }
        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            if(!set.contains(ch)) {
                System.out.print(ch);
                set.add(ch);
            }
        }
    }

    class Node {
        public Node next;
        public Node random;
        public int val;
        public Node(int val) {
            this.val = val;
        }
    }
    //复制链表
    public Node copyRandomList(Node head) {
        Node cur = head;
        Map<Node,Node> map = new HashMap();
        while(cur != null) {
            Node node = new Node(cur.val);
            map.put(cur,node);
            cur = cur.next;
        }
        cur = head;
        while(cur != null) {
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        return map.get(head);
    }

    //只出现一次的单词
    public int singleNumber(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for(int i = 0; i < nums.length; i++) {
            if(set.contains(nums[i])) {
                set.remove(nums[i]);
            }else {
                set.add(nums[i]);
            }
        }
        for(int i = 0;i < nums.length;i++) {
            if(set.contains(nums[i])) {
                return nums[i];
            }
        }
        return -1;
    }
}
